import os
import django
import datetime
from apscheduler.schedulers.blocking import BlockingScheduler

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Automatedtestplatform.settings")
django.setup()

from apps.app01 import models
from utils.RequestHandler import run_case


def job():
    """
    实现定时任务的逻辑实现
    """
    # 循环it表的it_end_time字段，判断该字段的值是否是当天，如果是当天的，就执行其内的所有用例
    it_obj = models.It.objects.all()
    today = datetime.date.today()
    for item in it_obj:
        if item.it_end_time == today:
            run_case(item.api_set.all())


def foo():
    """定时任务"""
    scheduler = BlockingScheduler()
    scheduler.add_job(job, "interval", seconds=1000, id='job')  # 每隔5秒执行一次
    scheduler.start()
